@file:Suppress("unused")

package com.example.demo.model.blog

import xyz.erupt.annotation.*
import xyz.erupt.annotation.sub_erupt.*
import xyz.erupt.annotation.sub_field.*
import xyz.erupt.annotation.sub_field.sub_edit.*
import xyz.erupt.upms.model.base.*
import javax.persistence.*

@Erupt(
    name = "博客管理",
    linkTree = LinkTree(field = "blogCategory"),
)
@Table(name = "blog_article")
@Entity
class Blog : HyperModel() {
    @EruptField(
        views = [View(title = "标题图", type = ViewType.IMAGE)],
        edit = Edit(
            title = "标题图",
            notNull = true,
            type = EditType.ATTACHMENT,
            attachmentType = AttachmentType(type = AttachmentType.Type.IMAGE),
        ),
    )
    var image: String = ""

    @EruptField(
        views = [View(title = "标题")],
        edit = Edit(
            title = "标题",
            notNull = true,
            search = Search(vague = true),
            inputType = InputType(fullSpan = true),
        ),
    )
    var name: String = ""

    @EruptField(
        views = [View(title = "是否原创")],
        edit = Edit(title = "是否原创", notNull = true),
    )
    var original: Boolean = true

    @EruptField(
        views = [View(title = "是否发布")],
        edit = Edit(title = "是否发布", notNull = true),
    )
    var publish: Boolean = false

    @EruptField(
        views = [View(title = "推荐等级")],
        edit = Edit(
            title = "推荐等级",
            notNull = true,
            type = EditType.CHOICE,
            choiceType = ChoiceType(
                vl = [VL(value = "0", label = "正常"),
                    VL(value = "10", label = "一级推荐"),
                    VL(value = "20", label = "二级推荐"),
                    VL(value = "30", label = "三级推荐")],
            ),
        ),
    )
    var recommendedLevel: Int = 0

    @ManyToOne
    @EruptField(
        views = [View(title = "分类", column = "name")],
        edit = Edit(title = "分类", notNull = true, type = EditType.REFERENCE_TREE),
    )
    var blogCategory: BlogCategory? = null

    @EruptField(
        views = [View(
            title = "标签",
            template = "value&&value.replace(/\\|/g,'<span class=\"text-red\"> | </span>')",
        )],
        edit = Edit(
            title = "标签",
            notNull = true,
            type = EditType.TAGS,
            tagsType = TagsType(fetchHandler = [BlogTagHandler::class]),
        ),
    )
    var tag: String = ""

    @Lob //文章内容较多定义为大文本类型
    @EruptField(
        views = [View(title = "内容", type = ViewType.HTML)],
        edit = Edit(title = "内容", notNull = true, type = EditType.HTML_EDITOR),
    )
    var content: String = ""

    @EruptField(
        views = [View(title = "备注")],
        edit = Edit(title = "备注", type = EditType.TEXTAREA),
    )
    var remark: String? = null

    @EruptField(views = [View(title = "点击数")])
    var clickNum: Int = 0  //需要通过前端接口向数据库写入！

}